package net.pm.core.entities.db;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import net.pm.common.toolkit.StringUtils;
import net.pm.core.entities.PMCommandEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * The persistent class for the pmuser database table.
 * PM用户实体类
 */
@Entity
@Table(name="pmuser")
public class Pmuser  extends PMCommandEntity<Pmdept> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3954814474144585699L;
	private Long id;
	private String address;
	private Date addTime;
	private String email;
	private String identity;
	private Boolean isAdmin;
	private String nickName;
	private String passWord;
	private String phone;
	private Short sex;
	private Short status;
	private String userName;
	private Pmdept pmdept;
	private Set<UserPower> userPowers;
	private Boolean isDelete;
	
	private District district;
	private Province province;
	private City city;

	
	public static final Short SEX_FEMALE = Short.valueOf("0");		//女
	public static final Short SEX_MALE = Short.valueOf("1");		//男
	
	public static final Short STATUS_DISABLE = Short.valueOf("0");	//禁用
	public static final Short STATUS_ENABLE = Short.valueOf("1");	//启用
	
	
	@SuppressWarnings("unused")
	private String name;
	
    public Pmuser() {
    }

	public Pmuser(Long id) {
		super();
		this.id = id;
	}


	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="Id", unique=true, nullable=false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	@Column(name="Address", nullable=true, length=50)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}


    @Temporal( TemporalType.TIMESTAMP)
	@Column(name="AddTime")
	public Date getAddTime() {
		return this.addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}


	@Column(name="Email", nullable=true, length=50)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}


	@Column(name="Identity", nullable=true, length=18)
	public String getIdentity() {
		return this.identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}


	@Column(name="IsAdmin", nullable=true)
	public Boolean getIsAdmin() {
		return this.isAdmin;
	}

	public void setIsAdmin(Boolean isAdmin) {
		this.isAdmin = isAdmin;
	}


	@Column(name="NickName", nullable=true, length=20)
	public String getNickName() {
		return this.nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}


	@Column(name="PassWord", nullable=true, length=100)
	public String getPassWord() {
		return this.passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}


	@Column(name="Phone", nullable=true, length=20)
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}


	@Column(name="Sex", nullable=true)
	public Short getSex() {
		return this.sex;
	}

	public void setSex(Short sex) {
		this.sex = sex;
	}

	@Column(name="Status", nullable=true)
	public Short getStatus() {
		return this.status;
	}

	public void setStatus(Short status) {
		this.status = status;
	}

	@Column(name="UserName", nullable=true, length=20)
	public String getUserName() {
		return this.userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}



	//bi-directional many-to-one association to Pmdept
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DeptId", nullable=true)
	public Pmdept getPmdept() {
		return this.pmdept;
	}

	public void setPmdept(Pmdept pmdept) {
		this.pmdept = pmdept;
	}
	

	//bi-directional many-to-one association to UserPower
	@OneToMany(mappedBy="pmuser")
	@JsonIgnore
	public Set<UserPower> getUserPowers() {
		return this.userPowers;
	}

	public void setUserPowers(Set<UserPower> userPowers) {
		this.userPowers = userPowers;
	}

	@Column(name="IsDelete", nullable=true)
	public Boolean getIsDelete() {
		return isDelete;
	}


	public void setIsDelete(Boolean isDelete) {
		this.isDelete = isDelete;
	}


	@Transient
	public String getName() {
		if(StringUtils.isNotEmpty(this.nickName)){
			return this.nickName;
		}
		return this.userName;
	}


	//bi-directional many-to-one association to District
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DistrictId", nullable=true)
	@JsonIgnore
	public District getDistrict() {
		return this.district;
	}

	public void setDistrict(District district) {
		this.district = district;
	}
	

	//bi-directional many-to-one association to Province
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ProvinceId", nullable=true)
	@JsonIgnore
	public Province getProvince() {
		return this.province;
	}

	public void setProvince(Province province) {
		this.province = province;
	}
	

	//bi-directional many-to-one association to City
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="CityId", nullable=true)
	@JsonIgnore
	public City getCity() {
		return this.city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	@Override
	public int compareTo(Pmdept o) {
		// TODO Auto-generated method stub
		return 0;
	}
	
}